<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>8.自定义对象的原型设置</title>
</head>

<body>
  <script>

    let hd = { name: 'hd' };
    let parent = {
      name: "parent", show () {
        console.log(`parent method ${this.name}`);
      }
    };
    // 设置原型
    //console.log(hd.__proto__ == Object.prototype); //true
    Object.setPrototypeOf(hd, parent);
    console.log(hd);
    //{name: 'hd'}
    //name: "hd"
    //[[Prototype]]: Object
    //  name: "parent"
    //  [[Prototype]]: Object
    hd.show(); //hd   parent method hd this 指向调用它的对象 也就是hd ，this.name = hd
    parent.show();// parent method parent
    //查看原型
    console.log(Object.getPrototypeOf(hd)); //{name: 'parent', show: ƒ} 原型对象是parent
  </script>
</body>

</html>